package com.interview.javabasic.thread;

public class CASCase {
    public /*volatile*/ int value;

    public synchronized void add() {
        value++;
    }

    public static void main(String[] agrs){
        CASCase casCase = new CASCase();
        new Thread(new Runnable() {
            @Override
            public void run() {
                casCase.add();
                try {
                    Thread.sleep(2000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(casCase.value);
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                casCase.add();
                System.out.println(casCase.value);
            }
        }).start();
        
        System.out.println(casCase.value);
    }
}
